package org.grow.wind.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.grow.wind.common.LoanState;
import org.grow.wind.common.Result;
import org.grow.wind.dao.LoanApplyMapper;
import org.grow.wind.entity.LoanApply;
import org.grow.wind.entity.LoanQueryCondition;
import org.grow.wind.service.LoanApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: xwg
 * @CreateDate: 2025/9/2
 */
@RestController
@RequestMapping("/loan")

public class LoanController {

    @Autowired
    private LoanApplyService loanApplyService;

    @Autowired
    private LoanApplyMapper loanApplyMapper;

    //    新增 查询
    @PostMapping("/insert")
    public Result<LoanApply> insert(@RequestBody LoanApply loanApply) {
        loanApply.setId(0);
        loanApply.setLoadState(LoanState.toSubmit);
//        当前登录人
        loanApply.setApplier("zhangsan");
        loanApply.setAuditor(null);
        loanApply.setUpdateTime(LocalDateTime.now());
        loanApplyMapper.insert(loanApply);
        return Result.success(loanApply);
    }

    //    多条件分页查询
    @PostMapping("/query")
    public Result<IPage<LoanApply>> query(@RequestBody LoanQueryCondition qc) {
        IPage page = Page.of(qc.getPageNum(), qc.getPageSize());
        IPage<LoanApply> r = loanApplyMapper.dynamicQuery(page, qc);
//        System.out.println(r);
        return Result.success(r);
    }
}
